package studentManager;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DaoUtil {

	public static void main(String[] args) {

		// 声明JDBC objects.
		Connection con = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=test", "java46", "java46");
			stmt = con.createStatement();
			rs = stmt.executeQuery("select * from stu");
			while (rs.next()) {// 如果对象中有数据，就会循环打印出来
				System.out.println(rs.getString("id") + "," + rs.getString("name"));
			}
			// int i = stmt.executeUpdate("insert into student
			// values('0004','哈哈',GETDATE(),2);");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				if (con != null) {
					con.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

}
